classdef Creditor
    % Creditor Class
    properties
        LiquHoldings    = 0.2;      % (risk-adjusted) holdings of liquid assets
        LiquBenefCst    = 1;        % Scaling constant for liquidity benefits
        LiquBenefEla    = 1/2;      % Elasticity of liquidity benefits (specification 1)
        LiquBenefMax    = NaN;      % Maximimal liquidiy benefits
    end
    
    methods 
        function [Psi,DPsi,D2Psi] = getLiquBenef(obj)
            % Reduced-form liquidity benefits enjoyed by creditors
            % In the numerical examples, we use two specifications: 
            % -- no satiation: Psi = const * L^eta
            % -- satiation: Psi = const * min[PsiM, (L^eta - eta * Lmax^(eta-1) * L]
            %    with Lmax = [PsiM/(1-eta)]^(1/eta)

            L       = obj.LiquHoldings;
            cst     = obj.LiquBenefCst;
            ela     = obj.LiquBenefEla;
            Psi_max = obj.LiquBenefMax;
            
            % Point of satiation (if any)
            if ~isnan(Psi_max)
                L_max   = cst*(Psi_max/(1-ela))^(1/ela);
            end

            % No satiation
            if isnan(Psi_max)
                Psi     = cst*L.^ela;
                DPsi    = cst*ela*L.^(ela-1);
                D2Psi   = -cst*ela*(1-ela)*L.^(ela-2);

            % With satiation
            else
                Psi     = cst*(L.^ela-ela*L_max.^(ela-1)*L);
                DPsi    = cst*(ela*L.^(ela-1)-ela*L_max.^(ela-1));
                D2Psi   = cst*(-ela*(1-ela)*L.^(ela-2));

                idx_sat = (L>=L_max);
                Psi(idx_sat)     = Psi_max;
                DPsi(idx_sat)    = 0;
                D2Psi(idx_sat)   = 0;
            end
        end
    end
end